﻿//using LdApp.Common.MessageService;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Web;
//using System.Web.UI;
//using System.Web.UI.WebControls;

//namespace WebForm
//{
//    public partial class SendEmail : System.Web.UI.Page
//    {
//        protected void Page_Load(object sender, EventArgs e)
//        {

//        }

//        protected void Button1_Click(object sender, EventArgs e)
//        {
//            SendMessage();
//        }

//        /// <summary>
//        /// 给企业发邮件
//        /// </summary>
//        private void SendMessage()
//        {
//            //先看下打开邮件发送功能没
//            //if (System.Configuration.ConfigurationManager.AppSettings["IsSendMail_Ordering"].ToString() != "1")
//            //{
//            //    return;
//            //}

//            #region 获取配置信息
//            string accountPath = HttpContext.Current.Server.MapPath("~");// HttpContext.Server.MapPath("~");// HttpContext.Current.Server.MapPath;

//            //MessageAccount account = new MailMessageAccount();   

//            //////保留配置数据（初始化时暂时使用）
//            ////MessageAccountConfig c = new MessageAccountConfig();
//            ////c.AccountName = "myis007";
//            ////c.Account = "myis007@sina.com";
//            ////c.Password = "111111";
//            ////c.ServiceAddress = "smtp.sina.com";
//            ////c.DefaultSender = "myis007撰稿人";
//            ////account.Config = c;
//            ////account.SaveConfig(accountConfig);

//            //////获取配置信息
//            //account.LoadConfig(accountPath);

//            //account.SendMessage("接收人1", "59208230@qq.com", "一个测试", "这是新的测试的内容", DateTime.Now.ToShortDateString());            
//            //////ViewBag.Message = "发送成功";

          

//            //获取邮件模板
//            //string MailContent = getUrltoHtml(GetRootURI().ToString() + "/Template/EmailSendOrderingAdd.html");
//            //加入了内嵌的图片
//            string MailContent = getUrltoHtml(GetRootURI().ToString() + "/Template/EmailSend_1.html"); 

//            //获取配置值
//            /*
//            HostName：站点名称
//            HostUrl：站点连接
//            HostLogo：站点LOGO
//            HostEmail：站点系统邮箱
//            HostAD：站点广告
//            */

//            string subj = "邮件主题";// System.Configuration.ConfigurationManager.AppSettings["subj"].ToString();
//            string hostName = "站点名称";// System.Configuration.ConfigurationManager.AppSettings["HostName"].ToString();
//            string name1 = "名称2";// System.Configuration.ConfigurationManager.AppSettings["Name1"].ToString();
//            string yuming ="http://linwei.soshaw.com";// System.Configuration.ConfigurationManager.AppSettings["yuming"].ToString();

//            MailContent = MailContent.Replace("{HostName}", hostName);
//            MailContent = MailContent.Replace("{yuming}", yuming);
//            MailContent = MailContent.Replace("{HostUrl}", GetRootURI().ToString() + "/index.aspx");
//            MailContent = MailContent.Replace("{HostLogo}", GetRootURI().ToString() + "/Wap/images/wap-logo.jpg");


//            //替换本业务的数据
//            MailContent = MailContent.Replace("{ShopName}", "商铺名称");
//            MailContent = MailContent.Replace("{ProductName}","产品名称");
//            MailContent = MailContent.Replace("{OrderingManName}", "订购人名称");
//            MailContent = MailContent.Replace("{OrderingTime}", DateTime.Now.ToShortDateString());
//            MailContent = MailContent.Replace("{QQ}", "123456");
//            MailContent = MailContent.Replace("{MPhone}", "13999999999");
//            MailContent = MailContent.Replace("{TheMessage}", "这是留言内容");
//            MailContent = MailContent.Replace("{ProductUrl}", "这是产品url");

//            #endregion

//            string _mail = string.Empty;

//            //_mail = ViewState["mail"].ToString();
//            _mail="59208230@qq.com";
//           // _mail = "liukai25184@163.com";


//            if (string.IsNullOrEmpty(_mail.Trim()))
//            {
//                return;
//            }


//            MessageAccount msg = new MailAccount();

//            if (msg.LoadConfig(accountPath))
//            {

//                if (msg.SendMessage("商铺名称X", _mail, "您的产品有订购信息", MailContent, DateTime.Now.ToString()))
//                {
//                    //发送成功
//                    LogHelper.WriteEmailInfo("发送邮件成功");
//                    //**********************************************************
//                    //修改商家管理系统，邮件可以链接到这个页面
//                }
//                else
//                {
//                    //发送失败
//                    string err = string.Format("给商家【{0}】的邮箱“{1}”发送邮件失败!","演示商家");
//                    LogHelper.WriteError(err);

//                }
//            }
//            else
//            {
//                //写错误日志
//                LogHelper.WriteError("加载邮箱配置时出错");
//            }

//        }
//        #region 返回页面HTML代码
//        public string ErrorString = "";
//        public string getUrltoHtml(string Url)
//        {
//            try
//            {
//                System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url);
//                System.Net.WebResponse wResp = wReq.GetResponse();
//                System.IO.Stream respStream = wResp.GetResponseStream();
//                System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("gb2312"));
//                return reader.ReadToEnd();
//            }
//            catch (System.Exception ex)
//            {
//                this.ErrorString = ex.ToString();
//                return "Error";
//            }
//        }

//        /// <summary>
//        /// 取得网站的根目录的URL
//        /// </summary>
//        /// <returns></returns>
//        public static string GetRootURI()
//        {
//            string AppPath = "";
//            HttpContext HttpCurrent = HttpContext.Current;
//            HttpRequest Req;
//            if (HttpCurrent != null)
//            {
//                Req = HttpCurrent.Request;

//                string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority);
//                if (Req.ApplicationPath == null || Req.ApplicationPath == "/")
//                    //直接安装在   Web   站点   
//                    AppPath = UrlAuthority;
//                else
//                    //安装在虚拟子目录下   
//                    AppPath = UrlAuthority + Req.ApplicationPath;
//            }
//            return AppPath;
//        }
//        #endregion
//    }
//}